/*
 * @Author: hanmengjie 515044692@qq.com
 * @Date: 2022-06-16 18:46:24
 * @LastEditors: hanmengjie 515044692@qq.com
 * @LastEditTime: 2022-06-19 11:21:27
 * @FilePath: \doctor-pc\doctor_end\src\utils\axios.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import axios from "axios";
import store from "@/store";

//1、设置全局请求地址
<<<<<<< Updated upstream
<<<<<<< Updated upstream

const ConfigBaseURL = 'http://172.16.110.210:8080';

=======
const ConfigBaseURL = 'http://150.158.153.184:8080';
//2、使用create方法创建axios实例
>>>>>>> Stashed changes
=======
const ConfigBaseURL = 'http://150.158.153.184:8080';

//2、使用create方法创建axios实例
>>>>>>> Stashed changes
const Service = axios.create({
        baseURL: ConfigBaseURL, //设置默认地址
        timeout: 7000 //设置请求超时时间
    })
    //3、设置post请求的头部（不同的项目，值可能不同）

// Service.defaults.headers.post['Content-type'] = 'application/json;charset=UTF-8';
Service.defaults.withCredentials = true; //添加cookie



//4、拦截axios发起的所有请求
Service.interceptors.request.use(config => {
    console.log('请求拦截了');
    //    发起请求时带token
    //     config.headers['token'] = store.getters.token;
    console.log(config);
    return config;
}, err => {
    return Promise.reject(err);
});

//拦截所有的响应
Service.interceptors.response.use(response => {
    console.log('响应拦截了');
    if (response.data.token) {
        store.dispatch('setUserToken', response.data.token)
    }
    console.log(response);
    return response;
}, error => {
    /*  console.log('TCL:error', error);
      const msg = error.Message !== undefined ? error.Message : '';
      Message({
          message:'网络错误'+msg,
          type:'error',
          duration:3*1000
      })
      loadingInstance.close();*/
    return Promise.reject(error);
});
export default Service;